<template>
  <div class="app-container msg">
    <el-form :model="queryParam" ref="queryForm" :inline="true"  style="text-align: center; height: 87px;">
      <el-row style="margin: auto; width: 100%; text-align: center; height: 37px;">
          <h1 style="display: inline-block; margin-top: -4px; text-align: center; color: #8b836c; font-size: 1.5rem; letter-spacing: 1px; font-family: serif;">系统消息列表</h1>
      </el-row>
      <el-row style="margin-bottom: 7px">
        <el-form-item label="发送者用户名：">
          <el-input v-model="queryParam.sendUserName" placeholder="请输入发送者用户名"></el-input>
        </el-form-item>
        <el-form-item style="margin-left: 10px;">
          <el-button class="detailBtn" size="small" @click="$router.push('/message/send')">消息发送</el-button>
          <el-button class="qryBtn" size="small" @click="submitForm">查询</el-button>
        </el-form-item>
      </el-row>
    </el-form>

    <el-table
      v-loading="listLoading"
      :data="tableData"
      fit 
      highlight-current-row
      style="
        width: 99.2%;
        border: 1px solid rgb(220, 223, 230);
        margin-bottom: 12px;
        border-radius: 10px;
        over-flow: auto;
      "
      max-height="500px"
      :header-cell-style="{
        'color':'#ffffff',
        'border-bottom-radius': '1px',
        'font-size':'0.86rem',
        'height':'8px',
        'font-family': 'serif',
        'font-weight': '800',
        'background': '#a2997f',
        'border-right-color': '#b6b6b1',
        'border-bottom-color': '#b6b6b1',
        'border-width': '1.2px'
      }"
      border>
      <el-table-column prop="id" label="Id"  width="80" />
      <el-table-column prop="title" label="消息标题" show-overflow-tooltip/>
      <el-table-column prop="content" label="消息内容" show-overflow-tooltip />
      <el-table-column prop="receives" label="接收人"  width="100" />
      <el-table-column prop="readCount" label="已读数" width="100" />
      <el-table-column prop="receiveUserCount" label="接收人数" width="100" />
      <el-table-column prop="createTime" label="创建时间" width="190px"/>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParam.pageIndex" :limit.sync="queryParam.pageSize"
                @pagination="search"/>
  </div>
</template>

<script>

import Pagination from '@/components/Pagination'
import messageApi from '@/api/message'

export default {
  components: { Pagination },
  data () {
    return {
      queryParam: {
        sendUserName: null,
        pageIndex: 1,
        pageSize: 10
      },
      listLoading: true,
      tableData: [],
      total: 0
    }
  },
  created () {
    this.search()
  },
  methods: {
    search () {
      this.listLoading = true
      messageApi.pageList(this.queryParam).then(data => {
        const re = data.response
        this.tableData = re.list
        this.total = re.total
        this.queryParam.pageIndex = re.pageNum
        this.listLoading = false
      })
    },
    submitForm () {
      this.queryParam.pageIndex = 1
      this.search()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang='scss'>
.msg .el-pagination {
  white-space: nowrap;
  padding: 2px 5px;
  color: #303133;
  font-weight: bold;
  text-align: center;
}
</style>